#ifndef THREAD_HH
#define THREAD_HH

/*!
 * \file thread.hh
 * \brief contains a generic thread implementation
 * \author Xavier SCHMERBER
 * \version 1
 */

#include <pthread.h>

/*!
 * \brief The Thread class: Generic thread implementation
 *  - Should be inherited by any class requiring a threaded loop
 *
 *  - The thread require a launcher function to be used, see prototype below.
 *  - This function has to be passed as argument to the method createThread.
 *
 *  - void *thread_starter(void *data)
 *  - {
 *  -    ClassToStart *classInstance = reinterpret_cast<ClassToStart*>(data);
 *  -    classInstance->functionToStart();
 *  -    return (data);
 *  - }
 */
class Thread
{
private: // vars
    pthread_t     _thread;                                      // thread variable
    bool          _started;                                     // indicator for thread state

public: // interface methods
    /*!
     * \brief Thread: Standard constructor
     */
    Thread();                                                   // Standard constructor
    /*!
     * \brief ~Thread: Standard destructor
     */
    ~Thread();                                                  // Standard destructor

protected: // heritage methods
    /*!
     * \brief createThread: Initialize the thread with the function to call (see above)
     * \param func = The function to start in the thread (c function specifically designed for the class)
     * \param param = The class which needs to be threaded
     * \return true / false
     */
    bool createThread(void *(*func)(void *), void *param);      // Initialize the thread with the function to call (see above)
    /*!
     * \brief joinThread: Wait for the thread to finish
     * \return true / false
     */
    bool joinThread();                                          // Wait for the thread to finish
    /*!
     * \brief destroyThread: Delete the thread
     * \return true / false
     */
    bool destroyThread();                                       // Delete the thread

private: // internal methods
};

#endif // THREAD_HH
